 
package com.junitUtil.baseTest;	
import org.xml.sax.InputSource;

import com.junitUtil.listener.DatabaseInitListeners;
import com.junitUtil.listener.MockTestExecutionListeners;
import com.junitUtil.spring.DataBaseBean;
import com.junitUtil.spring.TestDataBaseConfig;
import com.junitUtil.spring.TestLoader;

import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.context.support.GenericApplicationContext;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.TestExecutionListeners;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.test.context.support.DependencyInjectionTestExecutionListener;
import org.springframework.test.context.transaction.TransactionalTestExecutionListener;


import ch.qos.logback.classic.LoggerContext;
import ch.qos.logback.classic.joran.JoranConfigurator;
import ch.qos.logback.core.joran.spi.JoranException;
import ch.qos.logback.core.util.StatusPrinter;

import java.io.StringBufferInputStream;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.lang.reflect.Modifier;
import java.math.BigDecimal;

import org.junit.runner.RunWith;
import org.slf4j.LoggerFactory;



/**
 * TODO(描述这个类的作用) 
 * 
 **/
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(loader = TestLoader.class, classes = { TestDataBaseConfig.class })
//@see TestContextManager.DEFAULT_TEST_EXECUTION_LISTENER_CLASS_NAMES
@TestExecutionListeners({  DatabaseInitListeners.class, MockTestExecutionListeners.class,  TransactionalTestExecutionListener.class ,DependencyInjectionTestExecutionListener.class })
public abstract class AbstractBaseTest implements ApplicationContextAware{
    public GenericApplicationContext context;
    public static DataBaseBean dataBaseBean=new DataBaseBean();
    
    @Override
    public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
        context = (GenericApplicationContext) applicationContext;
    }
    
    
    
      static   {
          StringBuilder sb =new StringBuilder();
          sb.append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>")
            .append("<configuration>")
                .append("<appender name=\"STDOUT\" class=\"ch.qos.logback.core.ConsoleAppender\">")
                    .append("<encoder>")
                        .append("<charset>UTF-8</charset>")
                        .append("<pattern>%d [%thread][%X{contextUuid}][%X{hostName}][%X{userName}][%X{requestTime}] %-5level %logger{68} %line - %msg%n</pattern>")
                    .append("</encoder>")
                .append("</appender>")
//                .append("<logger name=\"org.springframework\" additivity=\"false\"><level value=\"ERROR\" /><appender-ref ref=\"STDOUT\" /></logger>")
//                .append("<logger name=\"com.wjs.common\" additivity=\"false\"><level value=\"ERROR\" /><appender-ref ref=\"STDOUT\" /></logger>")
//                .append("<logger name=\"com.wjs\" additivity=\"false\"><level value=\"DEBUG\" /><appender-ref ref=\"STDOUT\" /></logger>")
//                .append("<logger name=\"com.hundsun.wjs\" additivity=\"false\"><level value=\"DEBUG\" /><appender-ref ref=\"STDOUT\" /></logger>")
                .append(" <logger name=\"java.sql\" additivity=\"false\"> <level value=\"DEBUG\" /> <appender-ref ref=\"STDOUT\" /> </logger>")
                .append("  <root level=\"INFO\"> <appender-ref ref=\"STDOUT\" /> </root>")
            .append("</configuration>");
          
          LoggerContext lc = (LoggerContext) LoggerFactory.getILoggerFactory();
          JoranConfigurator configurator = new JoranConfigurator();
          configurator.setContext(lc);
          lc.reset();
          try {
            configurator.doConfigure(new InputSource(new StringBufferInputStream(sb.toString())));
        } catch (JoranException e) {
            e.printStackTrace();
        }
          StatusPrinter.printInCaseOfErrorsOrWarnings(lc);
      }
}

